<meta content="text/html; charset=UTF-8; X-Content-Type-Options=nosniff" http-equiv="Content-Type" />
<style type="text/css">
    .redBorder{border: 1px solid red;}
    #share_body_select_file .k-upload-files{display: none;}
    #share_body_select_file .k-file{display: none;}
    #share_body_select_file .k-delete{margin-top: -1px; margin-left: -10px;}
    /*kendo upload*/
    #share_body_select_file .k-button{min-width:0; width:45px; padding:0;margin:0;}
    #share_body_select_file .k-upload-button{background-color: #6cbf43!important;float:right; height: 17px;}
    #share_body_select_file .k-upload-button-disable{background-color: #f4f4f4!important;float:right;color:#b7b7b7;}
    #share_body_select_file .k-upload-button span{height:17px; line-height:17px; font-size:9px;}

    #share_body_select_file .k-upload-files{clear:both; min-height:41px;display: none; padding-top:10px;}
    #share_body_select_file .k-upload-files li{min-width:42px; max-width:42px; padding:0; border:none; float:left; margin-right:12px; font-size:12px; height:48px;}

    #share_body_select_file .k-upload-status{left:16px; top:-3px; line-height:0;} 
    #share_body_select_file .k-upload-status button{width: 10px; height: 10px; margin-top: -1px; padding-left: 10px; margin-left: 17px;}
    #share_body_select_file .k-upload-status span{background:url("imgs/delete.png") no-repeat;overflow:visible;}

    #share_body_select_file .k-i-pdf, .k-i-PDF{height:40px; width:40px; background:url("imgs/pdfIcon40.png") no-repeat!important; display: block; }
    #share_body_select_file .k-i-txt, .k-i-TXT{height:40px; width:40px; background:url("imgs/txt40.png") no-repeat!important; display: block; }
    #share_body_select_file .k-i-doc, .k-i-docx, .k-i-DOC, .k-i-DOCX {height:40px; width:40px; background:url("imgs/docIcon40.png") no-repeat!important; display: block; }
    #share_body_select_file .k-i-xls, .k-i-xlsx, .k-i-XLS, .k-i-XLSX {height:40px; width:40px; background:url("imgs/xlsIcon40.png") no-repeat!important; display: block; }
    #share_body_select_file .k-i-ppt, .k-i-pptx, .k-i-PPT, .k-i-PPTX {height:40px; width:40px; background:url("imgs/ppt40.png") no-repeat!important; display: block; }
    #share_body_select_file .k-i-zip, .k-i-ZIP{height:40px; width:40px; background:url("imgs/zip40.png") no-repeat!important; display: block; }
    #share_body_select_file .k-i-jpeg, .k-i-jpg, .k-i-png, .k-i-gif, .k-i-bmp, .k-i-tiff, .k-i-tif, .k-i-JPEG, .k-i-JPG, .k-i-PNG, .k-i-GIF, .k-i-BMP, .k-i-TIFF, .k-i-TIF {height:40px; width:40px; background:url("imgs/img40.png") no-repeat!important; display: block; }
</style>
<style type="text/css" id="for_ipad"></style>
<div id="ss_share" style="display:none;">
    <div id="ss_share_body" class="wp_pl_15 wp_mr_15">
        <!-- The top of the window -->
        <div id="share_body_top">
            <!-- top icon -->
            <div id="share_body_top_icon" class="wp_mt_10 wp_h_15">
                <a href="javascript:void(0)" id="share_body_top_icon_quick" style="cursor:default;text-decoration:none;">
                    <i id="share_quick_icon" class="main_smartstream_e_10_10" onclick="change_share_quick_event_email(this.id)"></i>
                </a>
                <a href="javascript:void(0)" id="share_body_top_icon_event" style="cursor:default;text-decoration:none; display: none;" class="wp_ml_20">
                    <i id="share_event_icon" class="main_smartstream_y_10_10" ></i>
                </a>
                <a href = "javascript:void(0)" id="share_body_top_icon_email" style="cursor:default;text-decoration:none; display: none;" class="wp_ml_20">
                    <i id="share_email_icon" class="main_smartstream_s_10_10"></i>
                </a>
                <!-- <a href="#" id="share_body_top_icon_event" class="wp_ml_20">
                    <i id="share_event_icon" class="main_smartstream_y_10_10" onclick="change_share_quick_event_email(this.id)"></i>
                </a>
                <a href = "#" id="share_body_top_icon_email" class="wp_ml_20">
                    <i id="share_email_icon" class="main_smartstream_s_10_10" onclick="change_share_quick_event_email(this.id)"></i>
                </a> -->
            </div>
    
            <!-- Content -->
            <!-- To -->
            <table id='share_body_input_table' class="wp_mt_5">
                <tr id="share_body_content_to" class='wp_h_20'>
                    <td class="wp_w_48 wp_fz_12" style="line-height: 20px;">To</td>
                    <td>
                        <input id="share_body_content_to_input" type="text" class="wp_ml_10 wp_fz_12 wp_w_435" />
                    </td>
                    <!-- <input id="share_body_content_to_input" type="text" class="col_1_2 wp_ml_10 wp_h_20 wp_w_421 wp_pr_20 wp_fz_12" style="Border:solid 1px #d8d8d8;" /> -->
                    <!-- Right icon -->
                    <!-- <div class="wp_w_15 wp_mt_10 wp_h_20 right" style="position: absolute; right: 4px; top: -7px">
                        <a href = "#" id="share_body_top_consignee_info_input_to_select" class="wp_fz_12">
                            <i class="main_calendar_aa_10_10  right wp_mr_5"></i>
                        </a>
                    </div> -->
                <!-- </div> -->
                </tr>
                <!-- Subject -->
                <tr id="share_body_content_subject" class="wp_h_20">
                    <td class="wp_w_48 wp_fz_12 wp_pt_10" style="line-height: 20px;">Subject</td>
                    <td class="wp_pt_10">
                        <input id="share_body_content_subject_input" type="text" class="wp_ml_10 wp_fz_12 k-textbox wp_w_437" maxlength="250" />
                    </td>
                </tr>
                <!-- Tags -->
                <tr id="share_body_content_tags" class="wp_h_20">
                    <td class="wp_w_48 wp_fz_12 wp_pt_10" style="line-height: 20px;">Tags</td>
                    <td class="wp_pt_10">
                        <input id="share_body_content_tags_input" type="text" class="wp_ml_10 wp_fz_12 wp_w_435" maxlength="255" onfocus="$(this).parent().addClass('k-state-focused')" />
                    </td>
                </tr>
            </table>
            <!-- Time -->
            <div id="share_body_content_time" class="row wp_mt_10">
                <div id="share_body_content_time_label" class="col_1_2 wp_w_48 wp_h_20 wp_fz_12" style="line-height: 18px;">Time</div>
                <div id="share_body_content_time_input" class="col_1_2 wp_ml_10 wp_w_421 wp_fz_12">
                    <div class="row">
                        <input id="share_start_date_input" value="" class="col_1_5 wp_h_20 wp_w_70" style="Border:solid 1px #d8d8d8;" />
                        <!-- <input id="share_start_date_input" type="text" class="col_1_5 wp_h_20 wp_w_70" style="Border:solid 1px #d8d8d8;" />-->
                        <input id="share_start_time_input" type="text" class="col_1_5 wp_ml_10 wp_h_20 wp_w_70" style="Border:solid 1px #d8d8d8;" />
                        <div class="col_1_5 wp_ml_10 wp_h_20 wp_w_9" style="line-height: 18px;">to</div>
                        <input id="share_end_date_input" type="text" class="col_1_5 wp_ml_10 wp_h_20 wp_w_70" style="Border:solid 1px #d8d8d8;" />
                        <input id="share_end_time_input" type="text" class="col_1_5 wp_ml_10 wp_h_20 wp_w_70" style="Border:solid 1px #d8d8d8;" />
                    </div>
                </div>
            </div>
            <!-- Location -->
            <div id="share_body_content_location" class="row wp_mt_10" style="position: relative;">
                <div id="share_body_content_location_label" class="col_1_2 wp_w_48 wp_h_20 wp_fz_12" style="line-height: 18px;">Location</div>
                <div>
                    <input id="share_body_content_location_input" type="text" class="col_1_2 wp_ml_10 wp_h_20 wp_w_421 wp_pr_20 wp_fz_12" style="Border:solid 1px #d8d8d8;" />
                <!-- Right icon -->
                    <div class="wp_w_15 wp_mt_10 wp_h_20 right" style="position: absolute; right: 4px; top: -7px">
                        <a href = "#" id="share_body_content_location_input_icon" class="wp_fz_12" style="text-decoration:none;">
                            <i class="main_calendar_z_10_10 right wp_mr_5"></i>
                        </a>
                    </div>
                </div>
            </div>
            <!-- Agenda -->
            <div id="share_body_content_agenda" class="row wp_mt_10">
                <div id="share_body_content_agenda_label" class="col_1_2 wp_mt_90 wp_w_48 wp_h_20 wp_fz_12" style="line-height: 18px;">Agenda</div>
                <div id="share_event_kendo_editor_all_tools" class="col_1_2 wp_ml_10 wp_w_421 wp_fz_12">
                    <textarea id="share_event_kendo_editor"></textarea>
                </div>
            </div>
        </div>

        <!-- //kendo editor all tools -->
        <div id="share_body_kendo_editor_all_tools" class="wp_mt_10 wp_fz_12">
            <textarea id="share_quick_kendo_editor" class="wp_h_60"></textarea>
        </div>
        
        <!-- The bottom of the window -->
        <!-- //select file -->
        <!-- <input id="share_body_select_file_name" type="text" style="position:absolute;" class="wp_fz_12 wp_mt_12 wp_w_391" disabled="true" /> -->
        <table id="share_body_select_file_table" class="wp_mt_10">
            <tr id="share_body_select_file" class='wp_h_20'>
                <td class="left wp_w_445">
                    <!-- <input id="share_body_select_file_name" type="text" class="wp_fz_12 wp_mt_12 wp_w_391" disabled="true" /> -->
                    <input type="file" name="files" id="share_body_select_file_field" autocomplete="off" />
                </td>
                <td style="vertical-align:top;" class="wp_h_15 wp_w_58">
                    <button id="share_body_select_file_btn_attach" class="k-button right wp_w_45 wp_h_17 wp_fz_9 k-state-disabled" style="line-height:17px;text-align:center;margin-top: 1px;" type="button">Attach</button>
                </td>
            </tr>
        </table>
        
        <!-- Share button -->
        <table id="share_body_bottom_table" class="wp_mt_10 wp_mb_10">
            <tr>
                <td id="share_body_bottom_icon" class="left wp_w_357 wp_h_20" style="margin-top: 0px; padding-top: 0px;">
                    <!-- <div id="share_body_bottom_icon_simple" style="line-height: 20px;">
                        <a href = "#" id="share_body_bottom_icon_simple_expand" class="wp_fz_11 shareWinAColorLine" style="text-decoration: none;color: #00aaff;">
                            Expand
                            <img src="imgs/dropDownIcon_8x5.png">
                        </a>
                    </div> -->
                    <div id="share_body_bottom_icon_attachment_div" class="wp_mt_4" style="line-height: 20px;">
                        <a href="#" id="share_body_bottom_icon_attachment_pic" style="text-decoration:none;" title="Image">
                            <i class="main_calendar_k_10_10"></i>
                        </a>
                        <a href="#" id="share_body_bottom_icon_attachment_file" class="wp_ml_20" style="text-decoration:none;" title="Document">
                            <i class="main_calendar_m_8_10"></i>
                        </a>
                    </div>
                </td>
                <td id="share_body_bottom_button" class="right wp_w_140">
                    <button id="share_body_bottom_share_btn" class="k-button wp_w_50 wp_h_20 right wp_fz_11" type="button">Share</button>
                    <!-- <button class="btn-bf k-button wp_w_50 wp_h_20 wp_mr_20 right wp_fz_11" onclick="shareWindow.data('kendoWindow').close()" type="button">Cancel</button> -->
                </td>
            </tr>
        </table>
    </div>
</div>
<!-- function -->
<script  type="text/javascript">
    var smartstreamShareWinFunc = (function () {
        var tagsInput, shareWinFileAppointType , shareWindow = $("#ss_share"), shareWinSelectedFileNames, shareWinTagsInputFlag = false, shareWinCloseCallback = null, shareTopIconOldId, shareWinType, editHtml, winTitle = "Share", shareWinSelectedFile = [], shareWinSelectedFileContents = [], shareWinToAutocompleteList = [], shareWinResponseSuccessCode = ['WP1008', 'WP1001', 'WP1005', 'WP1003'], quickEditorDiv, quickEditorElem, quickEditor, toInput, toAutoC, eventEditorElem, eventEditor, startDateInput, selectFileElem, attachmentPicA, attachmentPicI, attachmentFileA, attachmentFileI, selectFileTable, selectFileNameInput, attachBtn, selectFileTr, quickIconI, subjectInputElem, attachmentIconsDiv, startTimeInputElem, endDateInputElem, endTimeInputElem, locationInputElem, topIconsDiv, subjectTrElem, timeDivElem, locationDivElem, agendaDivElem, tagsTrElem, loader = new Workport.Loader(shareWindow), loaderContent = {position:'center', imgColor:'white', textCSS:{'color':'white'}, boxCSS:{'opacity':'1'}}, browserType = Workport.getBrowser(), winWidth;

        quickEditorElem = $('#share_quick_kendo_editor');
        quickEditorElem.kendoEditor({
            tools: ["bold", "italic", "underline", "strikethrough", "foreColor", "subscript", "superscript", "insertOrderedList", "insertUnorderedList", "justifyLeft", "justifyCenter", "justifyRight", "viewHtml", "createLink"
            ]
        });
        quickEditor = quickEditorElem.data("kendoEditor");

        toInput = $("#share_body_content_to_input");
        toInput.kendoAutoComplete({dataTextField: "name", filter: "contains"});
        toAutoC = toInput.data("kendoAutoComplete");
        toInput.off('input').on('input', function (e) {
            toInput.data('kendoAutoComplete').search(this.value);
        });
        toInput.blur(function () {
            toAutoC.close();

            var mentionName = toInput.val(), type;
            if (mentionName.length > 0) {
                sameNames = $.grep(shareWinToAutocompleteList, function (obj, i){return obj.name == mentionName});
                if (sameNames.length == 1) {
                    type = sameNames[0].type;
                    if (type == 'C') {
                        headerHtmlFunc.getMentionUserList(sameNames[0].id, type, function() {loader.show();}, function() {loader.hide();}, function() {Workport.AtWho.atKendoEditor(quickEditor, type);});
                        return;
                    }
                }
            }
            Workport.AtWho.atKendoEditor(quickEditor, 'U');
        });

        tagsInput = $("#share_body_content_tags_input");
        // Workport.TagFunc.setTagsAutoComplete(tagsInput, function() {loader.show();}, function() {loader.hide();});
        // tagsInput.blur(function () {
        //     Workport.TagFunc.stopSearchTags();
        //     tagsInput.data('kendoAutoComplete').close();
        //     $(this).parent().removeClass('k-state-focused');
        // });

        tagsInput.keydown(function (e) {
            if (e.which == 9) {
                e.preventDefault();
                quickEditor.focus();
            }
        });

        winWidth = '531px';
        if (browserType == 'safari_mac') {
            winWidth = '552px';
            toInput.css({"width": "457px", 'line-height': '0px'});
            tagsInput.css({"width": "457px", 'line-height': '0px'});
            subjectInputElem.css({"width": "459px", 'line-height': '0px'});
        } else if (browserType == 'ipad') {
            $('#for_ipad').append('.k-tooltip-content {padding: 0px;}');
            $('#for_ipad').append('#share_body_content_tags_input{font-size:10px}');
            $('#for_ipad').append('#share_body_content_to_input{font-size:10px}');
            $('#for_ipad').append('.k-editor-toolbar>li{margin-right:4px}');
            $('#for_ipad').append('#share_body_content_tags_input-list{height:150px!important}');
        }

        editHtml = shareWindow.html();
        shareWindow.kendoWindow({width: winWidth, title: winTitle, modal: true, visible:false, resizable: false, draggable: false, actions: ["Close"], 
            close: function() {
                // shareWindow.empty();
                // shareWindow.html(editHtml);
                if(browserType == 'ipad'){
                    $('body').unbind('touchmove')
                }
                share_win_clear_input_val();
            },
            open: function () {
                shareWindow.prev().find("span.k-i-close").attr("id", "ss_share_win_kendo_close_icon");
                if(browserType == 'ipad'){
                    $('body').bind('touchmove',function(event){event.preventDefault()});
                }
            }
        });
        loader.setContent(shareWindow, loaderContent);

        function init () {
            subjectInputElem = $("#share_body_content_subject_input");
            tagsTrElem = $("#share_body_content_tags");
            quickEditorDiv = $("#share_body_kendo_editor_all_tools");
            selectFileTr = $("#share_body_select_file");
            quickIconI = $("#share_quick_icon");
            subjectTrElem = $("#share_body_content_subject");
            attachmentIconsDiv = $("#share_body_bottom_icon_attachment_div");
            startTimeInputElem = $("#share_start_time_input");
            endDateInputElem = $("#share_end_date_input");
            endTimeInputElem = $("#share_end_time_input");
            locationDivElem = $("#share_body_content_location");
            locationInputElem = $("#share_body_content_location_input");
            topIconsDiv = $("#share_body_top_icon");
            timeDivElem = $("#share_body_content_time");
            agendaDivElem = $("#share_body_content_agenda");

            attachBtn = $("#share_body_select_file_btn_attach");
            attachBtn.off().click(function () {
                if (selectFileNameInput.val() == "") {
                    return;
                }

                shareWinSelectedFileNames.push(selectFileNameInput.val());
                $('#share_body_select_file_table').find('.k-upload-files').show();
                selectFileNameInput.val("");
                
                var shareWinFileSize = shareWinSelectedFile.length, shareWinFileReader, shareWinSelectedAttechment, 
                    shareWinMaxAttechmentCount = 9; ////Can choose the number of attachments, Starting from 0
                
                selectFileTr.find("ul li:last").show();
                attachBtn.addClass("k-state-disabled");//Attach button disable
                // button disabled, Can't choose the file
                if (shareWinFileSize == shareWinMaxAttechmentCount) {
                    selectFileTr.find("input").css("cursor","default");
                    selectFileTr.find('input:file:last').prop('disabled', true);//Browse button enable
                    selectFileTr.find("div:eq(1)").addClass("k-upload-button-disable");//browse button disable
                }
                //get attachment base64 encode
                shareWinFileReader = new FileReader();
                shareWinFileReader.onload = function(e) {
                    shareWinSelectedFileContents.push(e.target.result.replace(/^.*?,/, ''));
                }
                shareWinSelectedAttechment = selectFileTr.find('.k-file:last').data().fileNames[0].rawFile;
                shareWinFileReader.readAsDataURL(shareWinSelectedAttechment);
                shareWinSelectedFile.push(shareWinSelectedAttechment);

                shareWindow.data("kendoWindow").center();
            });

            // quickEditorElem = $('#share_quick_kendo_editor');
            // if (!quickEditorElem.data("kendoEditor")) {
            //     quickEditorElem.kendoEditor({
            //         tools: ["bold", "italic", "underline", "strikethrough", "foreColor", "subscript", "superscript", "insertOrderedList", "insertUnorderedList", "justifyLeft", "justifyCenter", "justifyRight", "viewHtml", "createLink"
            //         ]
            //     });
            //     quickEditor = quickEditorElem.data("kendoEditor");
            // }

            // eventEditorElem = $("#share_event_kendo_editor");
            // eventEditorElem.kendoEditor({
            //     tools: ["bold", "italic", "underline", "strikethrough", "foreColor", "subscript", "superscript", "insertOrderedList", "insertUnorderedList", "justifyLeft", "justifyCenter", "justifyRight", "viewHtml"
            //     ]
            // });
            // eventEditor = eventEditorElem.data("kendoEditor");

            startDateInput = $("#share_start_date_input");
            startDateInput.kendoDatePicker();
            
            //select file
            selectFileElem = $("#share_body_select_file_field");
            selectFileElem.kendoUpload({
                localization: {
                    select: "Browse"
                },
                select: function(e) {
                    var fileType, alertMessage, file = e.files[0], liLastElem, fileCount = 0, specialChar = ["#", "%", "&", "*", ":", "<", ">", "?", "/", "{", "|", "}", "\\", "~", "\""];

                    selectFileNameInput.val('');
                    attachBtn.addClass("k-state-disabled");

                    if ($(".k-state-focused input:first").is(':hidden')) {
                        $(".k-state-focused input:first").remove();
                    }

                    liLastElem = selectFileTr.find("ul li:last");
                    if (liLastElem.is(':hidden')) {
                        liLastElem.remove();
                    }

                    shareWinFileAppointType.indexOf("jpeg") > -1 ? fileType = 0 : fileType = 1;
                    fileType == 0 ? alertMessage = "The image must be of type bmp, gif, jpeg, png, tiff" : alertMessage = "The file must be of type doc, docx, pdf, ppt, pptx, txt, xls, xlsx, zip";
                    //Check the file type
                    if (shareWinFileAppointType.indexOf(file.extension.toLowerCase().substring(1)) < 0) {
                        Workport.utils.alertMsg(winTitle, alertMessage, function(_data){});
                        return;
                    }
                    // Check file size < 50MB
                    if (file.size > (50 * 1024 * 1024)) {
                        fileType == 0 ? alertMessage = "The size of the image must be within <50 MB>." : alertMessage = "The size of the attachment must be within <50 MB> .";
                        Workport.utils.alertMsg(winTitle, alertMessage, function(_data){});
                        return;
                    }
                    // Check file count < 5
                    for (var i = 0; i < shareWinSelectedFile.length; i++) {
                        if (fileType == 0 && shareWinSelectedFile[i].type.match(/image.*/)) {
                            fileCount = fileCount + 1;
                        } else if (fileType == 1 && !shareWinSelectedFile[i].type.match(/image.*/)) {
                            fileCount = fileCount + 1;
                        }
                    }
                    if (fileCount == 5) {
                        fileType == 0 ? alertMessage = "You can only select five Image files!" : alertMessage = "You can only select five documents!";
                        Workport.utils.alertMsg(winTitle, alertMessage, function(_data){});
                        return;
                    }

                    for (var i = 0; i < specialChar.length; i++) {
                        if (file.name.indexOf(specialChar[i]) > -1) {
                            Workport.utils.alertMsg(winTitle, "The attachment name cannot contain any of the following special characters: '\\ ~ # % & * : \" < > ? / { | }'. Please rename and try again.", function(_data){});
                            return;
                        }
                    }
                    // Check same file name
                    if (!shareWinSelectedFileNames) {
                        shareWinSelectedFileNames = new Array();
                    } else {
                        if ($.inArray(file.name, shareWinSelectedFileNames) > -1) {
                            Workport.utils.alertMsg(winTitle, "An attachment with the same name already exists. Please rename the attachment and try again.", function(_data){});
                            return;
                        }
                    }

                    selectFileNameInput.val(file.name);
                    attachBtn.removeClass("k-state-disabled");
                },
                remove: function(e) {
                    for (var i = 0; i < shareWinSelectedFile.length; i++ ) {
                        if (shareWinSelectedFile[i].name == e.files[0].name) {
                            shareWinSelectedFile.splice(i, 1);
                            shareWinSelectedFileContents.splice(i, 1);
                            shareWinSelectedFileNames.splice(i, 1);
                            break;
                        }
                    }
                    //button enabled
                    var fileDiv = selectFileTr.find("div:eq(1)");
                    if (fileDiv.hasClass("k-upload-button-disable")) {
                        // $(".k-upload-button>input").css("cursor","pointer");
                        // $('.k-upload-sync').find('input:file:last').prop('disabled', false);//Browse button enable
                        selectFileTr.find("input:file:first").css("cursor","pointer");
                        selectFileTr.find('input:file:last').prop('disabled', false);//Browse button enable
                        fileDiv.removeClass("k-upload-button-disable");//browse button enable
                    }

                    if (shareWinSelectedFile.length == 0) {
                        selectFileTr.find("ul").css("display", 'none');
                    }
                }
            });
            if ($("#share_body_select_file_name").length == 0) {
                selectFileElem.parent().before('<input id="share_body_select_file_name" type="text" class="wp_fz_12 wp_pt_3 wp_w_391 wp_h_13 k-textbox" disabled="true" />');
                selectFileElem.parent().css("margin-top","1px");
            }
            
            // $('#share_body_bottom_icon_simple_expand').bind({
            //     click:function(e){
            //         shareWinType = 'q';
            //         change_share_quick_event_email("share_quick_icon");
            //     }
            // });
            
            selectFileTable = $('#share_body_select_file_table');
            selectFileTable.hide();
            selectFileNameInput = $("#share_body_select_file_name");
            selectFileNameInput.hide();
    
            attachmentPicA = $('#share_body_bottom_icon_attachment_pic');
            attachmentPicI = attachmentPicA.find("i");
            attachmentFileA = $('#share_body_bottom_icon_attachment_file');
            attachmentFileI = attachmentFileA.find("i");
            attachmentPicA.off().bind({
                click:function(e){
                    // Change icon
                    if (attachmentPicI.hasClass("header_win_e_10_10")) {
                        return;
                    } else {
                        shareWinFileAppointType = "jpeg, jpg, png, gif, bmp, tiff";
                        attachmentPicI.toggleClass("main_calendar_k_10_10 header_win_e_10_10");
                        attachmentPicA.css("cursor", "default");

                        if (attachmentFileI.hasClass("header_win_f_10_10")) {
                            attachmentFileI.toggleClass("main_calendar_m_8_10 header_win_f_10_10");
                            attachmentFileA.css("cursor", "pointer");
                        }   
                    }
                    if (selectFileTable.is(':hidden')) {
                        selectFileTable.show();
                        selectFileNameInput.show();
                    }
                    selectFileNameInput.val("");
                    attachBtn.addClass("k-state-disabled");
                }
            });

            attachmentFileA.off().bind({
                click:function(e){
                    // Change icon
                    if (attachmentFileI.hasClass("header_win_f_10_10")) {
                        return;
                    } else {
                        shareWinFileAppointType = "pdf, doc, docx, ppt, pptx, xls, xlsx, txt, zip";
                        attachmentFileI.toggleClass("main_calendar_m_8_10 header_win_f_10_10");                
                        attachmentFileA.css("cursor", "default");
                        
                        if (attachmentPicI.hasClass("header_win_e_10_10")) {
                            attachmentPicI.toggleClass("main_calendar_k_10_10 header_win_e_10_10");
                            attachmentPicA.css("cursor", "pointer");
                        }   
                    }
                    if (selectFileTable.is(':hidden')) {
                        selectFileTable.show();
                        selectFileNameInput.show();
                    }
                    selectFileNameInput.val("");
                    attachBtn.addClass("k-state-disabled");
                }
            });
            
            // add id for kendo editor iframe 
            quickEditorDiv.find("iframe").attr("id","home_share_win_keditor_iframe");
            quickEditorDiv.find('table.k-editor').css("height", 250 - 20);

            $("#share_body_bottom_share_btn").off().click(function () {
                var errFlag = false, notificationText, toName = toInput.val(), sameNames, shareWinData, attachContents = [], imageContents = [], fileContent, fileSuffix, tagsInputVal, lastLetter, subjectVal, msgButtons, 
                    types = ['jpeg','jpg','gif','bmp', 'png','tiff','tif','pdf','docx','doc','pptx','ppt','xlsx','xls','txt','zip'];

                if (toName.length == 0) {
                    errFlag = true;
                    shareWinCreateTooltip(toInput, 'Must enter a user name or community to proceed.');
                } else {
                    sameNames = $.grep(shareWinToAutocompleteList, function (obj, i){return obj.name == toName});
                    if (sameNames.length == 1) {
                        toInput.val(sameNames[0].name);
                    } else {
                        errFlag = true;
                        sameNames.length == 0 ? shareWinCreateTooltip(toInput, "Please input valid User/Community name.") : shareWinCreateTooltip(toInput, "Please complete User/Community name.");
                    }
                }
                //Checkout description len
                notificationText = quickEditor.value().replace(new RegExp("&nbsp;","g")," ");
                if (Workport.utils.getRealLength(notificationText) == 0) {
                    errFlag = true;
                    shareWinCreateTooltip(quickEditorDiv, "Must enter a description to proceed.");
                } else if (Workport.utils.getRealLength(notificationText) > 20000) {
                    errFlag = true;
                    shareWinCreateTooltip(quickEditorDiv, "Description must be less than 20000 characters.");
                }

                if (shareWinType == 'q') {
                    tagsInputVal = $.trim(tagsInput.val());
                    if (tagsInputVal) {
                        if (tagsInputVal.length > 255) {
                            errFlag = true;
                            shareWinCreateTooltip(tagsInput, "Tags must be less than <255> characters..");
                        } else if (community_profile_controller.do_check_input(tagsInputVal, 2)) {
                            shareWinCreateTooltip(tagsInput, "The allowed characters are Alpha-numeric # @ $ % &.");
                            errFlag = true;
                        }
                    }
                }

                subjectVal = $.trim(subjectInputElem.val());
                if (!subjectVal) {
                    shareWinCreateTooltip(subjectInputElem, "Must enter  the subject to proceed.");
                    errFlag = true;
                }

                if (errFlag) {return;}

                if (shareWinType =='s') {
                    shareWinData = {
                        "TargetId": sameNames[0].id,
                        "SubEntity": '',
                        "NotificationText": notificationText,
                        "NotificationTitle": '',
                        "Tags": '',
                        "NotificationType": sameNames[0].type,//shareWinSelectedUserType,
                        "EntityId": '1'
                    };
                    loader.show();
                    Workport.StreamAPI.share(function (data) {
                        loader.hide();
                        if ($.inArray(data.ResponseCode, shareWinResponseSuccessCode) == -1) {
                            Workport.utils.alertMsg(winTitle, data.ResponseMessage, function (_data){});
                        } else {
                            if (shareWinCloseCallback) {
                                shareWinCloseCallback();
                            }
                            shareWindow.data("kendoWindow").close();
                        }
                    }, shareWinData);
                } else if (shareWinType == 'q') {
                    if (selectFileNameInput.val()) {
                        Workport.utils.alertMsg(winTitle, "The browsed content is not attached to the post. Click 'Yes' to post with attachment or 'No' to post without attachment.", 
                            [
                                {
                                    name: 'No',
                                    action: function () {
                                        selectFileNameInput.val("");
                                        attachBtn.addClass("k-state-disabled");
                                        setData(tagsInputVal, sameNames[0].id, sameNames[0].type, notificationText, subjectVal);
                                    }
                                },{
                                    name: 'Yes',
                                    class: 'btn yes',
                                    action: function () {
                                        loader.show();
                                        var timer;
                                        attachBtn.click();
                                        timer = setTimeout(function () {
                                            if (shareWinSelectedFileContents.length > 0) {
                                                clearTimeout(timer);
                                                setData(tagsInputVal, sameNames[0].id, sameNames[0].type, notificationText, subjectVal);
                                            }
                                        }, 1000);
                                        
                                    }
                                }
                            ]
                        );
                    } else {
                        loader.show();
                        setData(tagsInputVal, sameNames[0].id, sameNames[0].type, notificationText, subjectVal);
                    }
                }
            });
        }

        function setData(_tagsVal, _userid, _userType, _notificationText, _subjectVal) {
            var fileContent, fileSuffix, attachContents = [], imageContents = [], lastLetter, shareWinData, types = ['jpeg','jpg','gif','bmp', 'png','tiff','tif','pdf','docx','doc','pptx','ppt','xlsx','xls','txt','zip'];
            for (var i = 0; i < shareWinSelectedFile.length; i++) {
                fileContent = new Object();
                fileContent.AttachmentName = shareWinSelectedFile[i].name.substr(0, shareWinSelectedFile[i].name.lastIndexOf("."));
                fileContent.Attachmentbytes = shareWinSelectedFileContents[i];

                fileSuffix = shareWinSelectedFile[i].name;
                fileSuffix = fileSuffix.substr(fileSuffix.lastIndexOf(".") + 1).toLocaleLowerCase();
                $.inArray(fileSuffix, types) > -1 ? fileContent.AttachmentType = fileSuffix : null;
                shareWinSelectedFile[i].type.match(/image.*/) ? imageContents.push(fileContent) : attachContents.push(fileContent);
            };
            lastLetter = _tagsVal.substr(_tagsVal.length - 1, 1);
            while (lastLetter == ',') {
                _tagsVal = _tagsVal.substr(0, _tagsVal.length - 1);
                lastLetter = _tagsVal.substr(_tagsVal.length - 1, 1);
            };
            
            shareWinData = {
                "TargetId": _userid,//shareWinSelectedUserid,
                "Featured": '',
                "SubEntity": '',
                "NotificationText": _notificationText,
                "NotificationTitle": _subjectVal,
                "Tags": _tagsVal,
                "NotificationType": _userType,//shareWinSelectedUserType,
                "EntityId": '1',
                "hyperlinkURL": '',
                "AtMentionedUsers": Workport.AtWho.getAtIds(_notificationText),
                "AttachContents": attachContents,
                "ImageContents": imageContents
            };
            
            Workport.StreamAPI.shareGeneric(function (data) {
                loader.hide();
                if ($.inArray(data.ResponseCode, shareWinResponseSuccessCode) == -1) {
                    Workport.utils.alertMsg(winTitle, data.ResponseMessage, function (_data){});
                } else {
                    if (shareWinCloseCallback) {
                        shareWinCloseCallback();
                    }
                    shareWindow.data("kendoWindow").close();
                }
            }, shareWinData);
        }

        function share_win_clear_input_val () {
            if (quickIconI.hasClass("main_smartstream_f_10_10")) {
                quickIconI.toggleClass("main_smartstream_f_10_10 main_smartstream_e_10_10");
            }

            toInput.val("");
            subjectInputElem.val("");
            tagsInput.val("");
            startDateInput.val("");
            startTimeInputElem.val("");
            endDateInputElem.val("");
            endTimeInputElem.val("");
            locationInputElem.val("");

            // quickEditor.value("qqqq");
            quickEditor.value("");
            quickEditorDiv.find("ul.k-editor-toolbar").find("a").removeClass("k-state-selected");
            quickEditorDiv.find("ul.k-editor-toolbar").find("a").attr("aria-pressed", 'false');
            // quickEditor.refresh();
            // eventEditor.value("");

            var fileUl = selectFileTr.find("ul"), shareWinDelFileSize = fileUl.find("li").size(), fileDiv;
            while (shareWinDelFileSize > 0) {
                shareWinDelFileSize--;
                fileUl.find("li:eq(" + shareWinDelFileSize + ")").remove();
            }

            selectFileNameInput.val("");

            if (attachmentPicI.hasClass("header_win_e_10_10")) {
                attachmentPicI.toggleClass("main_calendar_k_10_10 header_win_e_10_10");
                attachmentPicA.css("cursor", "pointer");
            }

            if (attachmentFileI.hasClass("header_win_f_10_10")) {
                attachmentFileI.toggleClass("main_calendar_m_8_10 header_win_f_10_10");
                attachmentFileA.css("cursor", "pointer");
            }

            fileDiv = selectFileTr.find("div:eq(1)");
            if (fileDiv.hasClass("k-upload-button-disable")) {
                selectFileTr.find("input:file:first").css("cursor","pointer");
                selectFileTr.find('input:file:last').prop('disabled', false);//Browse button enable
                // $(".k-upload-button>input").css("cursor","pointer");
                // $('.k-upload-sync').find('input:file:last').prop('disabled', false);//Browse button enable
                
                fileDiv.removeClass("k-upload-button-disable")
            }

            shareWinSelectedFile = [];
            shareWinSelectedFileContents = [];
            shareWinSelectedFileNames = [];
            shareWinToNames = [];
            shareWinToAutocompleteList = [];

            attachBtn.addClass("k-state-disabled");
        }

        // Show simple share window
        // function share_simple_win_creat () {
        //     shareWinType = 's';

        //     attachmentIconsDiv.hide();
        //     topIconsDiv.hide();
        //     subjectTrElem.hide();
        //     tagsTrElem.hide();
        //     timeDivElem.hide();
        //     locationDivElem.hide();
        //     agendaDivElem.hide();
        //     selectFileTable.hide();

        //     // $("#share_body_bottom_icon_simple_expand").show();
        //     quickEditorDiv.show();

        //     selectFileNameInput.hide();

        //     shareWindow.css("height", "334px");
        // }

        // Notification window
        function share_notification_win_create() {
            attachmentIconsDiv.show();
            topIconsDiv.show();
            subjectTrElem.show();
            timeDivElem.hide();
            locationDivElem.hide();
            agendaDivElem.hide();
            tagsTrElem.show();
            quickEditorDiv.show();
            //Hidden selected file icon
//            $('.k-upload-files').hide();
            $('#share_body_select_file_table').find('.k-upload-files').hide();
            $('.k-files').hide();
            selectFileNameInput.hide();

            shareWindow.css("height", "430");
            shareWindow.removeAttr("style");
        }

        function share_event_win_create () {
            //date default value
            var date =new Date();
            startDateInput.val((date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear());

            attachmentIconsDiv.show();
            timeDivElem.show();
            locationDivElem.show();
            agendaDivElem.show();
            tagsTrElem.hide();
            quickEditorDiv.hide();
        }

        function share_email_win_create () {
            timeDivElem.hide();
            locationDivElem.hide();
            agendaDivElem.hide();
            tagsTrElem.hide();
            quickEditorDiv.show();
            attachmentIconsDiv.hide();
        }

        function change_share_quick_event_email(shareWinTopIconId){
            if (shareWinTopIconId == shareTopIconOldId) {return;};
            var shareWinTopIconIId = ["share_quick_icon", "share_event_icon", "share_email_icon"];
            var shareWinTopIconIImg = [["main_smartstream_e_10_10", "main_smartstream_f_10_10"], 
                                          ["main_smartstream_y_10_10", "main_smartstream_x_10_10"], 
                                          ["main_smartstream_s_10_10", "main_smartstream_z_10_10"]];
            var share_win_top_icon_a_id = ["share_body_top_icon_quick", "share_body_top_icon_event", "share_body_top_icon_email"];

            for (var i = 0; i < 3; i++){
                if (shareTopIconOldId == shareWinTopIconIId[i]) {
                    $("#" + shareTopIconOldId).toggleClass(shareWinTopIconIImg[i][0] + " " + shareWinTopIconIImg[i][1]);
                    $("#" + share_win_top_icon_a_id[i]).attr("href","#");
                    $("#" + share_win_top_icon_a_id[i]).attr("style","cursor:pointer;text-decoration:none;");
                };

                if (shareWinTopIconId == shareWinTopIconIId[i]) {
                    $("#" + shareWinTopIconId).toggleClass(shareWinTopIconIImg[i][0] + " " + shareWinTopIconIImg[i][1]);
                    $("#" + share_win_top_icon_a_id[i]).attr("href","javascript:void(0)");
                    // $("#" + share_win_top_icon_a_id[i]).attr("style","cursor:default;text-decoration:none;");
                    $("#" + share_win_top_icon_a_id[i]).attr("cursor","pointer");

                    if (i == 0) {
                        share_notification_win_create();
                    } else if (i == 1) {
                        share_event_win_create();
                    } else {
                        share_email_win_create();
                    }
                }
            }

            if (!selectFileTable.is(':hidden')) {
                selectFileTable.hide();
            };

            shareTopIconOldId = shareWinTopIconId;
        }

        function shareWinCreateTooltip (_elem, _msg) {
            _elem.kendoTooltip({
                content: _msg,
                position: "right",
                hide: function() {
                    _elem.data('kendoTooltip').destroy();
                }
            });
            _elem.data('kendoTooltip').show();
        }

        return {
            // Create share window
            share_win_create : function (cb, toName, toId, type) {
                init();

                shareTopIconOldId = "";
                shareWinCloseCallback = cb;

                shareWinType = 'q';
                change_share_quick_event_email("share_quick_icon");

                shareWindow.data("kendoWindow").center();
                shareWindow.data("kendoWindow").open();
                
                // get user list/
                if (toName) {
                    shareWinToAutocompleteList.push({"id": toId, "name": toName,"type": type});
                    if(browserType == 'ipad'){
                        toInput.attr("readonly","true"); 
                        toInput.attr("onFocus","this.blur()");
                    }else{
                        toInput.attr("disabled","true");
                    }
                    toInput.val(toName);

                    Workport.AtWho.atKendoEditor(quickEditor, type);
                } else {
                    // loader.show();
                    toInput.removeAttr("disabled");
                    toInput.val("");
                    shareWinToAutocompleteList = WP_USER_LIST.concat(WP_COMMUNITY_LIST);
                    Workport.AtWho.atKendoEditor(quickEditor, 'U');
                }

                toAutoC.setDataSource(shareWinToAutocompleteList);

                quickEditorDiv.find(".k-editable-area").find("iframe").attr("id","home_share_win_keditor_iframe");
            }
        }
    })(); 
</script>